Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: listpayments --count_total_payments should honor --creation_date_start and --creation_date_end #8565

Closed
wants to merge 4 commits into from

Conversation

violetguos
Copy link

@violetguos violetguos commented Mar 18, 2024

Change Description

Fixes #8530

Add extra check for the creation start and end date
Only query all payments if those are not specified.

Added check for totalCount in existing test cases where the CountTotal flag isn't set.

Steps to Test

Run unit tests and integration tests

Pull Request Checklist

Testing

  • Your PR passes all CI checks.
  • Tests covering the positive and negative (error paths) are included.
  • Bug fixes contain tests triggering the bug to prevent regressions.

Code Style and Documentation

📝 Please see our Contribution Guidelines for further guidance.

Summary by CodeRabbit

  • New Features

    • Enhanced payment query capabilities to include filtering by creation date range.
  • Tests

    • Added test for querying payments with specified start and end creation dates.

Copy link
Contributor

coderabbitai bot commented Mar 18, 2024

Important

Auto Review Skipped

Auto reviews are limited to the following labels: llm-review. Please add one of these labels to enable auto reviews.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository.

To trigger a single review, invoke the @coderabbitai review command.

Walkthrough

The recent update enhances the QueryPayments function by introducing a condition that checks for specific start and end creation dates, alongside the existing CountTotal check, before executing certain operations. Additionally, a new test case has been added to verify the functionality of querying payments within a specified date range while also considering the total count.

Changes

Files Change Summary
.../channeldb/payments.go Added condition for CreationDateStart and CreationDateEnd in QueryPayments.
.../channeldb/payments_test.go Added test "query max transaction with start and end creation time" in TestQueryPayments.

🐰✨
In the realm of code, where changes abound,
A rabbit hopped in, making barely a sound.
With a flick and a hop, it weaved its spell,
Enhancing the code, making it swell.
"Fear not," it whispered, with a mischievous grin,
"For every end is merely a new begin."
🌟📅🚀

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@violetguos
Copy link
Author

@coderabbitai review

@violetguos violetguos marked this pull request as ready for review March 19, 2024 00:59
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b0552da and f7528b91e1431ed108f8b686c70f101cd896a34d.
Files selected for processing (2)
  • channeldb/payments.go (1 hunks)
  • channeldb/payments_test.go (1 hunks)
Additional comments: 1
channeldb/payments_test.go (1)
  • 475-485: The new test case "query max transaction with start and end creation time" is well-structured and aligns with the PR objectives to enhance querying mechanisms by adding checks for creation timestamp start and end dates. It correctly tests the scenario where both CreationDateStart and CreationDateEnd are specified along with CountTotal set to true, ensuring the functionality works as intended without causing regressions.

@violetguos violetguos changed the title add creation ts start end check in query all fix: listpayments --count_total_payments should honor --creation_date_start --creation_date_end Mar 19, 2024
@violetguos violetguos changed the title fix: listpayments --count_total_payments should honor --creation_date_start --creation_date_end fix: listpayments --count_total_payments should honor --creation_date_start and --creation_date_end` Mar 20, 2024
@violetguos violetguos changed the title fix: listpayments --count_total_payments should honor --creation_date_start and --creation_date_end` fix: listpayments --count_total_payments should honor --creation_date_start and --creation_date_end Mar 20, 2024
@violetguos violetguos changed the title fix: listpayments --count_total_payments should honor --creation_date_start and --creation_date_end fix: listpayments --count_total_payments should honor --creation_date_start and --creation_date_end Mar 20, 2024
Copy link
Member

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Could you fix the commit messages as required by our contribution guidelines?

Check for uninit int with 0 instead of !
- should be 0 for everyone
except the query with count total set to true
@violetguos
Copy link
Author

@yyforyongyu I have address your comment. could you please review?

@saubyk saubyk added the rpc Related to the RPC interface label Mar 30, 2024
@saubyk saubyk requested a review from ellemouton March 30, 2024 21:43
@saubyk saubyk added the payments Related to invoices/payments label Apr 1, 2024
@violetguos
Copy link
Author

@ellemouton could you please review the changes? thanks

@ellemouton
Copy link
Collaborator

@violetguos - it is in my review queue. Please have patience :)

Copy link
Collaborator

@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @violetguos 🙏

I dont think this is the behaviour we want though. If count_total is set at the same time as start and end dates, then we should count the total number of payments between those start and end dates.

Other comments:

  • please remove the [skip-cl] in the title of the last commit. We definitely want the CI to run here.
  • If you change a line of code in one commit - then it should be formatted correctly in that commit. Ie, dont add another commit to fix the formatting.

Comment on lines +600 to 603
query.CreationDateEnd == 0 {
// It will only take effect if CreationDateStart and
// CreationDateEnd are not specified.
var (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think this is the behaviour we want. I think that we still want to count how many payments there were but we just want to count the ones that happened between the given start and end times.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the feedback @ellemouton

the original bug report by @AndySchroder specifies that

$ lncli listpayments --creation_date_start 1650000000 --count_total_payments --creation_date_end 1650000001|grep total_num_payments
    "total_num_payments": "0"
$

it seems like the original issue had a different interpretation on the expected behaviour

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont agree. In that example he is specifying a difference in start and end time of 1 second (millisecond?). So it is expected that there are no payments during that time

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that time difference was specified to assume there were no payments between that short period of time.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think this is the behaviour we want. I think that we still want to count how many payments there were but we just want to count the ones that happened between the given start and end times.

yes, this was the original purpose of the bug

Copy link

@AndySchroder AndySchroder Apr 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the feedback @ellemouton

the original bug report by @AndySchroder specifies that

$ lncli listpayments --creation_date_start 1650000000 --count_total_payments --creation_date_end 1650000001|grep total_num_payments
    "total_num_payments": "0"
$

it seems like the original issue had a different interpretation on the expected behaviour

no, please understand the interpretation that @ellemouton is providing. she understands bug report correctly.

Copy link
Collaborator

@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my reply to your comment & also see the previous review for comments about commit structuring :)

* [Fix a bug](https://github.com/lightningnetwork/lnd/pull/8565) where
`listpayments --count_total_payments` flag disregarded `--creation_date_start`
and `--creation_date_end`. The payments between the dates would be queried
instead of the total payments if the dates were supplied.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is not correct.

@lightninglabs-deploy
Copy link

@yyforyongyu: review reminder
@violetguos, remember to re-request review from reviewers when ready

@violetguos
Copy link
Author

Sorry for the misinterpretation of the original example provided in the bug report. I currently don't have the capacity to implement the fix due to the change of scope.

@violetguos violetguos closed this May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
payments Related to invoices/payments rpc Related to the RPC interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug]: lncli listpayments --count_total_payments should honor --creation_date_start --creation_date_end
6 participants